package com.woniu.microassetserver.controller;


import com.github.pagehelper.PageInfo;
import com.woniu.microassetserver.service.DomaintypeService;
import com.woniu.microcommonsserver.entity.AssetsParameterEntity;
import com.woniu.microcommonsserver.entity.DomaintypeEntity;
import com.woniu.microcommonsserver.entity.ResultMsg;
import com.woniu.microcommonsserver.param.PageResult;
import com.woniu.microcommonsserver.param.ResponseMsg;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 
 *
 * @author luoyue
 * @email 1316756108@qq.com
 * @date 2021-01-22 11:09:05
 */
@RestController
@RequestMapping("/domaintype")
public class DomaintypeController {

    @Resource
    private DomaintypeService domaintypeServiceImpl;



    @RequestMapping(value = "/more", produces = {"application/json;charset=utf-8"})
    public ResultMsg saveDomaintype(@RequestBody DomaintypeEntity domaintypeEntity) {

        System.out.println("添加");

        ResultMsg resultMsg = new ResultMsg(200, "新增成功", null);
        domaintypeServiceImpl.saveDomaintype(domaintypeEntity);
        System.out.println(domaintypeEntity);
        System.out.println("新增成功");
        return resultMsg;
    }


    @PutMapping(value = "/id/{id}", produces = {"application/json;charset=utf-8"}) /*AssetsParameterBean assetsParameterBean, @PathVariable("id") Long id*/
    public ResultMsg updateDomaintype(@PathVariable("id") Long id,DomaintypeEntity domaintypeEntity) {
        ResultMsg resultMsg = new ResultMsg(200, "更新成功", null);
        System.out.println(id);
        domaintypeServiceImpl.updateDomaintype(domaintypeEntity);
        return resultMsg;
    }


    @DeleteMapping(value = "/delete/{id}", produces = {"application/json;charset=utf-8"})
    public ResultMsg deleteDevSystem(@PathVariable("id") Long id) {

        System.out.println("添加");

        ResultMsg resultMsg = new ResultMsg(200, "删除成功", null);

        domaintypeServiceImpl.deleteDomaintype(id);

        System.out.println("删除成功");

        return  resultMsg;

    }


    @GetMapping(value = "/selectAll", produces = {"application/json;charset=utf-8"})
    public ResponseMsg selectDevType(Integer pageNum, Integer pageSize, DomaintypeEntity domaintypeEntity) {

        System.out.println("哦呵呵查询");


        PageInfo<DomaintypeEntity> pageInfo =domaintypeServiceImpl.findAllByParams(pageNum, pageSize, domaintypeEntity);

        PageResult<DomaintypeEntity> pageResult=new PageResult<DomaintypeEntity>();
        pageResult.setRows(pageInfo.getList());
        pageResult.setTotal(pageInfo.getTotal());

        return ResponseMsg.builder().code(200).msg("查询陈工").data(pageResult).build();
    }


    @GetMapping(value = "/findAll", produces = {"application/json;charset=utf-8"})
    public ResponseMsg findDomaintype() {

        System.out.println("哦呵呵yayaya查询");


        List<DomaintypeEntity> domaintypeEntities =domaintypeServiceImpl.findAll();

        PageResult<DomaintypeEntity> pageResult=new PageResult<DomaintypeEntity>();
        pageResult.setRows(domaintypeEntities);

        return ResponseMsg.builder().code(200).msg("查询陈工").data(pageResult).build();
    }

    @GetMapping(value = "/getOneById", produces = {"application/json;charset=utf-8"})
    public ResponseMsg findDomaintype1(Long id) {

        System.out.println("哦呵呵yayaya查询");


        DomaintypeEntity domaintypeEntitie =domaintypeServiceImpl.getOneById(id);


        return ResponseMsg.builder().code(200).msg("查询陈工").data(domaintypeEntitie).build();
    }



    @GetMapping(value = "/getAssetById", produces = {"application/json;charset=utf-8"})
    public ResponseMsg findAssets(Long id) {

        System.out.println("zichan");


        List<AssetsParameterEntity> assetsParameterEntities =domaintypeServiceImpl.findAssetById(id);
        System.out.println(assetsParameterEntities);

        return ResponseMsg.builder().code(200).msg("查询陈工").data(assetsParameterEntities).build();
    }


}
